<%@page import="com.beans.MenuInfo"%>
<%@page import="java.util.List"%>
<%@page import="com.beans.AdminInfo"%>
<%@page import="com.dao.MenuDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="css/edittable.css"  >
<link rel="stylesheet" type="text/css" href="css/maintable.css">
<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<script >
$(function() {
	var lists=${ints}
	$('input[type="checkbox"][name="ck_id"]').each( function() {
		if($.inArray(parseInt($(this).val()), lists)>=0){
			$(this).attr("checked",true);
		}
     });
	
	$(".one").click(function(){
		var s=$(this).closest("td").next().children();
		if(this.checked){
			s.each(function() {
				$(this).find(".two").attr("checked","checked");
			});
		}else{
			s.each(function() {
				$(this).find(".two").removeAttr("checked");
			})
		}	
	});
	$(".two").click(function(){
		var s=$(this).closest("td").prev();
		if(this.checked){
				s.find(".one").attr("checked","checked");
		}else {
			var beat=false;
			$(this).closest("td").children().each(function() {
				if($(this).find(".two")[0].checked){
					beat=true;
				}
			});
			if(beat==false){
				s.find(".one").removeAttr("checked");
			};
		}
	});
})
</script>
</head>
<body>
<div class ="div_title">
			<div class="div_titlename"> <img src="images/san_jiao.gif" ><span>角色权限绑定</span></div>
			<div class="div_titleoper">角色名称：&ensp;${role.roleName}</div>
	</div>
	<%
		List<MenuInfo> menuLists = new MenuDao().getAllMenus();
		request.setAttribute("menuLists", menuLists);
	%>
	<form action="RoleServlet.do"  method="post">
	<input type="hidden" name="flag" value="roleUpdate">
	<input type="hidden" name="id" value="${role.id}">
	<table class="main_table">
		<tr>
			<th>一级菜单</th>
			<th>二级菜单</th>
		</tr>
		<c:forEach items="${menuLists}" var="one_menu">
			<tr>
				<td>
					<input type="checkbox" name="ck_id" value="${one_menu.id}" class="one"/> ${one_menu.getMenuName()}
				</td>
				<td>
				
				<c:forEach items="${one_menu.getTwoMenuInfos()}" var="menu_2">
					<div><input type="checkbox" name="ck_id" value="${menu_2.id}" class="two"/> ${menu_2.getMenuName()}</div>
				</c:forEach>
				
				</td>
			</tr>
		</c:forEach>
		
	</table>
	<br>
	&ensp;  &ensp;  &ensp;  &ensp;  &ensp;  
	<input class="form_btn" type="submit" value="提交" /> 
	<input type="button" onclick="window.location.href='RoleServlet.do?flag=manage';" class="form_btn" value="返回" />
	</form>
<script >$(function() {
	var msg="${msg}";if(msg!=""){alert("${msg}");}
})</script>
</body>
</html>